package com.example.wiki.config;

import com.example.wiki.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

//实现WebMvcConfigurer
@Configuration
public class SpringMvcConfig implements WebMvcConfigurer {

    //注入登录拦截器的对象
    @Resource
    LoginInterceptor loginInterceptor;

    //添加拦截器对象及配置拦截规则
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")//拦截所有的请求  exclude
                .excludePathPatterns(//exclude排除某些请求地址，不需要被拦截
                        "/test/**",
                        "/redis/**",
                        "/user/userLogin",
                        "/category/allList",
                        "/ebook/**",
                        "/doc/all/**",
                        "/doc/vote/**",
                        "/doc/find-content/**",
                        "/snapshot/**",
                        "/doc/findContentById/**",
                        "/ebook-snapshot/getStatistic/**"
                );
    }
}

